package com.example.springboot_myproject.Mapper;

import com.example.springboot_myproject.Model.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper {
    //新增用户（注册）
    @Insert("INSERT INTO user(email,password,salt,confirm_code,"+
            "activation_time,is_valid)"+" VALUES (#{email},#{password},#{salt},"+
            "#{confirmCode},#{activationTime},#{isValid} )")

    int insertUser(User user);
//    根据确认码查询用户，
    @Select("SELECT email,activation_time FROM user WHERE confirm_code = #{confirmCode}")
    User selectUserByConfirmCode(@Param("confirmCode") String confirmCode);
//    根据确认吗查询用户，并且修改状态值为1（可用状态）
    @Update("UPDATE user SET is_valid = 1 WHERE confirm_code = #{confirmCode}")
    int updateUserByConfirmCode(@Param("confirmCode") String confirmCode);

//    登录
    @Select("SELECT email,password,salt FROM user WHERE email = #{email} AND is_valid = 1")
    List<User> selectUserByEmail(@Param("email") String email);
}